package com.jy.modules.cims.fundsbalance.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.jy.modules.cims.fundsbalance.service.DiscountInquiryService;
import com.jy.platform.core.message.DataMsg;
import com.jy.platform.core.message.PageParameter;
import com.jy.platform.core.message.PageUtil;
import com.jy.platform.core.message.QueryReqBean;
import com.jy.platform.restservice.exception.AbaboonException;
import com.jy.platform.restservice.web.base.BaseController;

/**
 * @classname: TCMmFundsrepayStreamController
 * @description: 定义  t_c_mm_fundsrepay_stream 控制层
 * @author:  jieyue
 */
@Controller
@Scope("prototype")
@RequestMapping("/discountInquiry")
public class DiscountInquiryController extends BaseController{

    @Autowired
    private DiscountInquiryService discountInquiryService;
    
    /**
     * 通过 Controller 请求 跳转 进入至相关 页面
     */
    @RequestMapping(value = "/prepareExecute/{operate}")
    public ModelAndView execute(@PathVariable("operate") String operate) throws AbaboonException {
    	ModelAndView model = new ModelAndView();
        
        if("toQueryPage".equals(operate)){//跳转至 查询页面
        	model.setViewName("cims/discountInquiry/queryDiscountInquiry");
        }
        
        return model;
    }
    
    /**
     * @author jieyue
     * @description:查询分页列表
     * @date 2017-04-24 17:05:32
     * @param request
     * @param dto
     * @param dataMsg
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/queryListDiscountInquiry")
    @ResponseBody
    public DataMsg queryListDiscountInquiry(HttpServletRequest request,  @ModelAttribute DataMsg dataMsg) throws Exception {
        
    	Map<String, Object> searchParams = new HashMap<String, Object>();
    	searchParams.put("cooperorgCode", this.getParameterString("cooperorgCode")) ;
    	searchParams.put("contractCode", this.getParameterString("contractCode")) ;
    	searchParams.put("creditCode", this.getParameterString("creditCode")) ;
    	searchParams.put("startDate", this.getParameter("startDate")) ;
    	searchParams.put("endDate", this.getParameter("endDate")) ;
        QueryReqBean params = new QueryReqBean();
        params.setSearchParams(searchParams);
    	PageParameter pageInfo = PageUtil.toPageParameter(dataMsg);
		params.setPageParameter(pageInfo);
		
        List<Map<String,Object>> list = discountInquiryService.searchDiscountInquiryByPaging(params.getSearchParams());
        
        dataMsg.setData(list);
        dataMsg.setTotalRows(pageInfo.getTotalCount());
        return dataMsg;
    }
    
}
